<?php
$_doc = array();
$_doc['title'] = L('tab_category_allocate_userlist');
?>
<include file="pAdmin:header" />
<table class="tabmenu" cellspacing="0">
    <tbody>
        <tr>
            <td class="wedge">&nbsp;</td>
            <td class="wmenu"><a href="__URL__/index">{%tab_category_list}</a></td>
            <td class="wmenu"><a href="__URL__/add">{%tab_category_add}</a></td>
            <td class="wmenu here"><a href="__URL__/allocate"><span>{%tab_category_allocate}</span></a></td>
            <td>&nbsp;</td>
        </tr>
    </tbody>
</table>
<div class="main">
        <p class="editpage finder">
        <?php echo sprintf(L('page_title_allocate_category'),$user['account']); ?>
        </p>
    <ul class="fnc">
        <li><button type="button" class="btn primary" onclick="act('save')">{%action_save}</button></li>
        <li><button type="button" class="btn" onclick="back()">{%action_previous}</button></li>
    </ul>
    <form id="ipsForm" name="mainForm" method="post" action="__URL__">
        <input type="hidden" name="a" value="allocate"/>
        <input type="hidden" name="step" value="3" />
        <input type="hidden" name="uid" value="{$user['id']}" />
        <table class="data" id="gridInst">
            <thead>
                <tr>
                    <th>{%column_name}</th>
                    <th>{%column_purview_range}</th>
                </tr>
            </thead>
            <tbody class="grid" id="catesBody">
<?php
    $nbsp=array();
    $nbsp[0]="";
    $nbsp[1]="&nbsp;";

    function getNbsp($level,&$nbsp){
        if( ! array_key_exists($level,$nbsp)){
            $last=$nbsp[intval($level)-1];
            $nbsp[$level]=$last.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        }
        return $nbsp[$level];
    }
?>
                <iterate name="cates" id="vo">
                    <tr>
                        <td>
                            {$vo['ply']|getNbsp=###,$nbsp}
                            <input id="s{$vo['id']}" type="checkbox" name="id[]" value="{$vo['id']}"/>
                            {$vo['name']}
                        </td>
                        <td>
                            <input id="pk{$vo['id']}" type="checkbox" name="range[]" value="{$vo['id']}"/>&nbsp;<label for="pk{$vo['id']}">{%all_doc}</label>
                        </td>
                    </tr>
                </iterate>
                <tr style="display:none">
                    <td><input id="s0" type="checkbox" name="sid[]" checked value="0"/></td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </form>
    <ul class="fnc">
        <li><button type="button" class="btn primary" onclick="act('save')">{%action_save}</button></li>
        <li><button type="button" class="btn" onclick="back()">{%action_previous}</button></li>
    </ul>
</div>
<script type="text/javascript">
    $(window).addEvent('domready',function(){
        //禁止事件的传播
        $("catesBody").getElements("input").each(function(ips){
            if('range[]'==ips.getProperty('name')){
                ips.addEvent('click',function(event){
                    event.stopPropagation();
                });
                ips.getNext().addEvent('click',function(event){
                    event.stopPropagation();
                });
            }
        });
        //初始用户已有授权项目
        var tmp;
        <iterate name="allocate" id="vo">
        tmp=$("s{$vo['category']}");
        if(tmp){
            tmp.checked=true;
            tmp.parentNode.parentNode.className='rowChecked';
            if('{$vo['allocate']}'=='y'){
                $("pk{$vo['category']}").checked=true;
            }
        }
       </iterate>
    });
    function back(){ history.back(); }
</script>
<include file="pAdmin:footer" />